﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HFK.DxFluentUI.LanguageModel;
using HFK.DxFluentUI.LanguageModel.HorizontalGrid;
using HFK.DxFluentUI.LanguageModel.Editors;
using HFK.DxFluentUI.Editors;

namespace HFK.DxFluentUI.HorizontalGrid.Columns
{
  public class PropertyColumnEditorContext<ComponentType, PropertyType> : EditableEditorElement<PropertyType, ContinuationAndElement<HorizontalGridColumnElement<ComponentType>>>
  {
    public PropertyColumnEditorContext(PropertyColumnContext<ComponentType> parent, PropertyType[] data)
    {
      m_parent = parent;
      m_data = data;
    }

    public ContinuationAndElement<HorizontalGridColumnElement<ComponentType>> InDropdownBoxEditor(Action<DropdownBoxElement<PropertyType>> configuration)
    {
      DropdownBoxContext<PropertyType> dropDownBox = DropdownBoxContext<PropertyType>.Create();
      configuration(dropDownBox);

      dropDownBox.ImplementingControl.DataSource = m_data;

      m_parent.ImplementingControl.ColumnEdit = dropDownBox.ImplementingControl;
      m_parent.GridControl.RepositoryItems.Add(dropDownBox.ImplementingControl);

      return new ContinuationAndContext<HorizontalGridColumnElement<ComponentType>>(m_parent);
    }

    public ContinuationAndElement<HorizontalGridColumnElement<ComponentType>> InDropdownGridEditor(Action<DropdownGridElement<PropertyType>> configuration)
    {
      DropdownGridContext<PropertyType> dropDownGrid = DropdownGridContext<PropertyType>.Create();
      configuration(dropDownGrid);

      dropDownGrid.ImplementingControl.DataSource = m_data;

      m_parent.ImplementingControl.ColumnEdit = dropDownGrid.ImplementingControl;
      m_parent.GridControl.RepositoryItems.Add(dropDownGrid.ImplementingControl);

      return new ContinuationAndContext<HorizontalGridColumnElement<ComponentType>>(m_parent);
    }

    private PropertyColumnContext<ComponentType> m_parent;
    private PropertyType[] m_data;
  }
}
